package wechat.rcv.controller;

import com.shrcl.engineerprocess.domain.Notification;
import edu.fudan.mylang.pf.IObjectFactory;
import org.apache.log4j.Logger;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import wechat.rcv.controller.StatusResponse;

@RestController
@SuppressWarnings("all")
public class ChangeNotifiedStatus {
  private final static Logger logger = Logger.getLogger(ChangeNotifiedStatus.class.getName());
  
  @Autowired
  private IObjectFactory entities;
  
  @RequestMapping(value = "/changestatus", method = RequestMethod.GET)
  public StatusResponse process(final Long notificationId) {
    ChangeNotifiedStatus.logger.info("=========>ChangeNotifiedStatus.processs<============");
    final StatusResponse result = new StatusResponse();
    try {
      final Notification n = this.entities.<Notification>get(Notification.class, notificationId);
      n.confirm("微信确认");
      Boolean _isConfirmed = n.isConfirmed();
      String _plus = ("=========>ChangeNotifiedStatus.isConfirmed<============" + _isConfirmed);
      ChangeNotifiedStatus.logger.info(_plus);
      Boolean _isConfirmed_1 = n.isConfirmed();
      result.success = _isConfirmed_1;
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
        final Exception e = (Exception)_t;
        result.success = Boolean.valueOf(false);
        e.printStackTrace();
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
    return result;
  }
}
